/*
 * Copyright 2008. Mount Sinai Hospital, Toronto, Canada.
 * 
 * Licensed under the Apache License, Version 2.0. You
 * can find a copy of the license at:
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * IN NO EVENT SHALL MOUNT SINAI HOSPITAL BE LIABLE TO ANY PARTY FOR DIRECT, 
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST 
 * PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, 
 * EVEN IF MOUNT SINAI HOSPITAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
 * DAMAGE.
 * 
 * MOUNT SINAI HOSPITAL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND 
 * ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". 
 * MOUNT SINAI HOSPITAL HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
 */

package com.sinai.mshab.format;

import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.TextBoxBase;
import com.google.gwt.user.client.ui.Widget;
//import com.sinai.mshab.widgets.RadioCollection;

/**
 * This class takes in a widget and tells you if it's blank or not.
 * 
 * @author serge
 * 
 */
public class BlankChecker {

	/**
	 * Checks if the given widget is blank or not
	 * 
	 * @param widget
	 *            the widget to check
	 * @return true if the widget is checked, false otherwise.
	 */
	public static boolean isBlank(Widget widget) {

		// first check textboxes
		if (widget instanceof TextBoxBase) {
			String value = ((TextBoxBase) widget).getText();

			// if the value is null or has no length it's blank
			if (value == null || value.trim().length() == 0) {
				return true;
			}
		}
		// then check checkboxes.
		else if (widget instanceof CheckBox) {
			if (!((CheckBox) widget).isChecked()) {
				return true;
			}
		}
		// check radio collections
//		else if (widget instanceof RadioCollection) {
//			return !((RadioCollection)widget).isChecked();
//		}
		
		return false;
	}
}
